﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NLog;
using NLog.Targets;
using NLog.Config;

namespace BlobStroage
{
    public partial class NlogForm : Form
    {
        public NlogForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //SetNLog();
            /*
            1.   Trace－最常见的记录信息，一般用于普通输出；
            2.   Debug－同样是记录信息，不过出现的频率要不Trace少一些，一般用来调试程序；
            3.   Info－信息类型的消息
            4.   Warn－警告信息，一般用于比较重要的场合
            5.   Error－错误信息
            6.   Fatal－致命异常信息。一般来讲，发生致命异常之后程序将无法继续执行。
            */
            //Logger logger = LogManager.GetLogger("Example");
            Logger logger = LogManager.GetCurrentClassLogger();
            logger.Trace("trace log message");
            logger.Debug("debug log message");
            logger.Info("info log message");
            logger.Warn("warn log message");
            logger.Error("error log message");
            logger.Fatal("fatal log message");
            logger.Info("info log message11111111111");
        }

        public void SetNLog()
        {
            LoggingConfiguration config = new LoggingConfiguration();

            ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget();
            config.AddTarget("console", consoleTarget);

            FileTarget fileTarget = new FileTarget();
            config.AddTarget("file", fileTarget);

            consoleTarget.Layout = "${date:format=HH//:MM//:ss} ${logger} ${message}";
            fileTarget.FileName = "${shortdate}/${windows-identity:domain=false}.txt";
            fileTarget.Layout = "${date} ${logger} ${message}";

            LoggingRule rule1 = new LoggingRule("*", LogLevel.Debug, consoleTarget);
            config.LoggingRules.Add(rule1);

            LoggingRule rule2 = new LoggingRule("*", LogLevel.Debug, fileTarget);
            config.LoggingRules.Add(rule2);

            LogManager.Configuration = config;
        }
    }
}
